{% load i18n %}
{% load static %}

{% load appearance_tags %}
{% load common_tags %}
{% load navigation_tags %}
{% load smart_settings_tags %}

<div class="row">
    <div class="col-xs-12">
        {% if not object_list %}
            {% include 'appearance/partials/list_header.html' %}
            <div class="well center-block">
                {% include 'appearance/partials/no_results.html' %}
            </div>
        {% else %}
            {% include 'appearance/partials/list_header.html' %}

            {% navigation_resolve_menu name='multi item' sort_results=True source=object_list.0 as links_multi_menus_results %}

            {% navigation_get_source_columns source=object_list only_identifier=True as source_columns_identifier %}
            {% navigation_get_source_columns source=object_list exclude_identifier=True as source_columns_non_identifier %}

            <div class="well center-block">
                <div class="table-responsive">
                    <table class="table table-condensed table-striped">
                        <thead>
                            {% if not hide_header %}
                                <tr>
                                    {% if links_multi_menus_results %}
                                        <th class="first"></th>
                                    {% endif %}

                                    {% if not hide_object %}
                                        <th>{% trans 'Identifier' %}</th>
                                    {% else %}
                                        {% if source_columns_identifier %}
                                            <th>
                                                <span style="white-space: nowrap">
                                                    {% if source_columns_identifier.0.is_sortable %}
                                                        <a href="{% navigation_get_sort_field_querystring column=source_columns_identifier.0 %}">{{ source_columns_identifier.0.label }}</a>
                                                            {% navigation_source_column_get_sort_icon column=source_columns_identifier.0 as icon_sort %}
                                                            {% if icon_sort %}
                                                                <span class="appearance-list-column-sort-icon">
                                                                    {{ icon_sort.render }}
                                                                </span>
                                                            {% endif %}
                                                    {% else %}
                                                        <span class="appearance-list-column-label">{{ source_columns_identifier.0.label }}</span>
                                                    {% endif %}
                                                    {% include 'appearance/partials/column_help_text.html' with source_column=source_columns_identifier.0 %}
                                                </span>
                                            </th>
                                        {% endif %}
                                    {% endif %}

                                    {% if not hide_columns %}
                                        {% for source_column in source_columns_non_identifier %}
                                            <th>
                                                <span style="white-space: nowrap">
                                                    {% if source_column.is_sortable %}
                                                        <a href="{% navigation_get_sort_field_querystring column=source_column %}">{{ source_column.label }}</a>
                                                            {% navigation_source_column_get_sort_icon column=source_column as icon_sort %}
                                                            {% if icon_sort %}
                                                                <span class="appearance-list-column-sort-icon">
                                                                    {{ icon_sort.render }}
                                                                </span>
                                                            {% endif %}
                                                    {% else %}
                                                        <span class="appearance-list-column-label">{{ source_column.label }}</span>
                                                    {% endif %}
                                                    {% include 'appearance/partials/column_help_text.html' %}
                                                </span>
                                            </th>
                                        {% endfor %}
                                    {% endif %}

                                    {% for column in extra_columns %}
                                        <th>{{ column.name }}</th>
                                    {% endfor %}

                                    {% if not hide_links %}
                                        <th class="">&nbsp;</th>
                                    {% endif %}
                                </tr>
                            {% endif %}
                        </thead>
                        <tbody>
                            {% for object in object_list %}
                                <tr>
                                    {% if links_multi_menus_results %}
                                        <td>
                                            <input class="form-multi-object-action-checkbox check-all-slave checkbox" name="pk_{{ object.pk }}" type="checkbox" value="" />
                                        </td>
                                    {% endif %}

                                    {% if not hide_object %}
                                        <td>{% if not hide_link %}<a href="{{ object.get_absolute_url }}">{{ object }}</a>{% else %}{{ object }}{% endif %}</td>
                                    {% else %}
                                        {% if source_columns_identifier %}
                                            {% navigation_source_column_resolve column=source_columns_identifier.0 as column_value %}
                                            <td>
                                                {{ column_value }}
                                            </td>
                                        {% endif %}
                                    {% endif %}

                                    {% if not hide_columns %}
                                        {% for column in source_columns_non_identifier %}
                                            <td>
                                                <div class="{{ table_cell_container_classes }} {{ column.html_extra_classes }}">
                                                    {% navigation_source_column_resolve column=column as column_value %}{{ column_value }}
                                                    {# Use explicit 'as column_value ' to force date rendering #}
                                                </div>
                                            </td>
                                        {% endfor %}
                                    {% endif %}

                                    {% for column in extra_columns %}
                                        <td>{{ object|common_object_property:column.attribute }}</td>
                                    {% endfor %}

                                    {% if not hide_links %}
                                        <td class="last">
                                           <div class="btn-list">
                                                {% smart_setting "COMMON_COLLAPSE_LIST_MENU_LIST_FACET" as setting_common_collapse_list_menu_list_facet %}
                                                {% navigation_resolve_menu name='list facet' sort_results=True source=object as facet_menus_results %}
                                                {% if setting_common_collapse_list_menu_list_facet %}
                                                    {% if facet_menus_results %}
                                                        {% with facet_menus_results as action_menus_link_results %}
                                                            <div class="btn btn-xs dropdown">
                                                                {% with 'btn btn-default btn-outline btn-xs' as action_dropdown_classes %}
                                                                {% with 'true' as action_menu_disable_labels %}
                                                                {% trans 'Facets' as action_dropdown_label %}
                                                                    {% include 'navigation/actions_dropdown.html' %}
                                                                {% endwith %}
                                                                {% endwith %}
                                                            </div>
                                                        {% endwith %}
                                                    {% endif %}
                                                {% else %}
                                                    {% for facet_menu_results in facet_menus_results %}
                                                        {% for link_group in facet_menu_results.link_groups %}
                                                            {% with link_group.links as object_navigation_links %}
                                                            {% with 'btn btn-default btn-outline btn-xs' as link_classes %}
                                                                {% include 'navigation/generic_navigation.html' %}
                                                            {% endwith %}
                                                            {% endwith %}
                                                        {% endfor %}
                                                    {% endfor %}
                                                {% endif %}

                                                {% navigation_resolve_menu name='object' source=object sort_results=True as object_menus_results %}
                                                {% smart_setting "COMMON_COLLAPSE_LIST_MENU_OBJECT" as setting_common_collapse_list_menu_object %}
                                                {% if setting_common_collapse_list_menu_object %}
                                                    {% if object_menus_results %}
                                                        {% with object_menus_results as action_menus_link_results %}
                                                            <div class="btn btn-xs dropdown">
                                                                {% with 'btn btn-default btn-xs btn-danger' as action_dropdown_classes %}
                                                                {% with 'true' as action_menu_disable_labels %}
                                                                    {% include 'navigation/actions_dropdown.html' %}
                                                                {% endwith %}
                                                                {% endwith %}
                                                            </div>
                                                        {% endwith %}
                                                    {% endif %}
                                                {% else %}
                                                    {% for object_menu_results in object_menus_results %}
                                                        {% for link_group in object_menu_results.link_groups %}
                                                            {% with link_group.links as object_navigation_links %}
                                                                {% include 'navigation/generic_navigation.html' %}
                                                            {% endwith %}
                                                        {% endfor %}
                                                    {% endfor %}
                                                {% endif %}
                                            </div>
                                        </td>
                                    {% endif %}
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        {% endif %}
    </div>
</div>
